package dog.gui;

import constants.STATUS;
import containers.Person;
import dog.model.Model;

//This represents a cell in a list of participants. It is reevaluated whenever the list changes.
public class ParticipantCell
	{
	private int personID;
	private int status;
	private Model model;
	public ParticipantCell(Model model,int personID,int status)
		{
		this.model=model;
		this.personID=personID;
		this.status=status;
		}
	public String getString()
		{
		if (model==null)
			return "Prototype value Aaaaaa";
		
		Person p = model.getPerson(personID);
		if (p==null)//This will happen if we allow deletion
			return "Deleted";
		else
			return p.email;
		}
	public String getStatus()
		{
		if (status==STATUS.ACCEPTED)
			return "Accepted";
		else if (status==STATUS.DENIED)
			return "Denied";
		else if (status==STATUS.LEFT)
			return "Left";
		else if (status==STATUS.NOTREPLIED)
			return "Not replied";
		else if (status==STATUS.OWNER)
			return "Owner";
		else
			return "Invalid status";
		}
	@Override
	public boolean equals(Object o)
		{
		if (o instanceof ParticipantCell)
				return (((ParticipantCell) o).personID==personID);
			else
				return false;
		}
	public int getPersonID()
		{
		Person p = model.getPerson(personID);
		return p.personID;
		}
	/**
	 * Set the status. This does not change any associated appointment or notify the server, it is only cosmetic.
	 */
	public void setLocalStatus(int status)
		{
		this.status=status;
		}
	}
